/*
 * Copyright (c) 2020, chao
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020-09-08     chao         the first version
 */

#include "emxgui.h"
#include "gui_demo.h"
#include "x_libc.h"

enum BUTTON_ID {
    ID_BTN_START        = 0x1100,
    ID_BTN_BACK         = ID_BTN_START,
    ID_BTN_TIME,
    ID_BTN_OPTION,
    ID_BTN_DEPARTMENT,
    ID_BTN_TICKET_HEAD,
    ID_BTN_TICKET_TAIL,
    ID_BTN_PASSWORD,
    ID_BTN_PAYMENT,
    ID_BTN_COMMODITY,
    ID_BTN_SERVICE,
    ID_BTN_TAX_RATE,
    ID_BTN_LANGUAGE,
    ID_BTN_FACTORY_CODE,
    ID_BTN_END,
};

static const wchar_t *text_buff[] = {
    L"Date and time setup",
    L"Option setup",
    L"Department setup",
    L"Ticket head setup",
    L"Ticket tail setup",
    L"Password setup",
    L"Payment method setup",
    L"Commodity registartion",
    L"Service registartion",
    L"Tax rate setup",
    L"Language setup",
    L"Factory code setup",
};

LRESULT setting_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    RECT rc;
    GetClientRect(hwnd, &rc);
    
    switch (msg)
    {
    case WM_CREATE:
    {
		int columnButtonCount = ID_BTN_END-ID_BTN_START;
		int buttonWidth = GUI_XSIZE - 10;
		int buttonHeight = 30;
		int buttonYDistance = 5;
		int i;
		int x = 5, y = 30;

		for (i = 0; i < columnButtonCount; i++)
		{			
			CreateWindow(BUTTON, text_buff[i], WS_VISIBLE, x, y, buttonWidth, buttonHeight, hwnd, ID_BTN_TIME+i, NULL, NULL);
			y += buttonHeight + buttonYDistance;
		}  
        return TRUE;
    }
    
    case WM_PAINT:
    {
        PAINTSTRUCT ps;
        HDC hdc;
        RECT rc;
        
        hdc =BeginPaint(hwnd,&ps);
        GetClientRect(hwnd, &rc);
        //rc.w /= 2;
        //DrawText(hdc, L"ABCDEFG", -1, &rc, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
        EndPaint(hwnd,&ps);
        break;
    }
        
    default:
        return DefDesktopProc(hwnd, msg, wParam, lParam);
    }
    return WM_NULL;
}

void gui_demo_setting(void)
{
    HWND hwnd;
    WNDCLASS wcex;
    MSG msg;

    wcex.Tag = WNDCLASS_TAG;
    wcex.Style = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc = setting_proc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = NULL;
    wcex.hIcon = NULL;
    wcex.hCursor = NULL;

    hwnd = CreateWindowEx(WS_EX_LOCKPOS, &wcex, L"Setting", 
    WS_VISIBLE|WS_CLIPCHILDREN, 
    0, STATUS_BAR_HEIGHT, GUI_XSIZE, GUI_YSIZE-STATUS_BAR_HEIGHT, NULL, 0, NULL, NULL);

    ShowWindow(hwnd, SW_SHOW);

    while (GetMessage(&msg, hwnd))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}


